package com.lizhi.menu.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.lizhi.menu.common.response.Result;
import com.lizhi.menu.domain.Store;
import com.lizhi.menu.service.IStoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 店铺Controller
 *
 * @author lizhi
 * @date 2023-05-19
 */
@RestController
@RequestMapping("/system/store")
@Api(tags = "店铺管理")
public class StoreController {
    @Autowired
    private IStoreService storeService;

    /**
     * 查询店铺列表
     */
    @GetMapping("/list")
    @ApiOperation("查询店铺列表")
    public Result list(Store store) {

        List<Store> list = storeService.selectStoreList(store);
        return Result.ok(list);
    }

    /**
     * 查询店铺列表
     */
    @GetMapping("/my")
    @ApiOperation("查询店铺列表")
    public Result my(Store store) {
        store.setUseId(StpUtil.getLoginId().toString());
        List<Store> list = storeService.selectStoreList(store);
        return Result.ok(list);
    }

    /**
     * 获取店铺详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取店铺详细信息")
    public Result getInfo(@PathVariable("id") Long id) {
        return Result.ok(storeService.selectStoreById(id));
    }

    /**
     * 新增店铺
     */
    @PostMapping
    @ApiOperation("新增店铺")
    public Result add(@RequestBody Store store) {
        store.setUseId(StpUtil.getLoginId().toString());
        return Result.ok(storeService.insertStore(store));
    }

    /**
     * 修改店铺
     */
    @PutMapping
    @ApiOperation("修改店铺")
    public Result edit(@RequestBody Store store) {
        return Result.ok(storeService.updateStore(store));
    }

    /**
     * 删除店铺
     */
    @DeleteMapping("/{ids}")
    @ApiOperation("删除店铺")
    public Result remove(@PathVariable Long[] ids) {
        return Result.ok(storeService.deleteStoreByIds(ids));
    }
}
